//
//  CZQEidtJobViewController.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/14.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQEidtJobViewController.h"
#import "CZQEidtJobView.h"
#import "MOFSPickerManager.h"
#import "SourceAlertView.h"
@interface CZQEidtJobViewController ()


@property(nonatomic,weak)CZQEidtJobView *eidtJobView;

@end

@implementation CZQEidtJobViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"编辑求职意向";
    
    //右侧按钮
    
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(sureBtnClick)];
    
    [rightButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:CSBlackColor,NSFontAttributeName:MidFont} forState:UIControlStateNormal];
    
    [rightButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:CSBlackColor,NSFontAttributeName:MidFont} forState:UIControlStateHighlighted];
    
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    
    
    
    [self createSubView];
}

#pragma mark 创建子视图
-(void)createSubView{
    
    CZQEidtJobView *eidtJobView = [[CZQEidtJobView alloc] init];
    
    
    //地址选择
    eidtJobView.addressBtnView.choseLabel.text = self.resumeModel.HopeCity;
    
    [eidtJobView.addressBtnView.choseBtn addTarget:self action:@selector(addressSelect)];
    
//    [myInfoView.sureBtn addTarget:self action:@selector(sureBtnClick)];
    
    eidtJobView.backgroundColor = BackGroundColor;
    
    [self.view addSubview:eidtJobView];
    
    //求职状态
    [eidtJobView.jobStatuBtnView.choseBtn addTarget:self action:@selector(showJobStatu)];
    eidtJobView.jobStatuBtnView.choseLabel.text = self.resumeModel.HopeStatus;
    
    //期望职位
    [eidtJobView.jobWorkBtnView.choseBtn addTarget:self action:@selector(showJobWork)];
    eidtJobView.jobWorkBtnView.choseLabel.text = self.resumeModel.HopePosition;
    
    //薪水
    [eidtJobView.jobMoneyBtnView.choseBtn addTarget:self action:@selector(showJobMoney)];
    eidtJobView.jobMoneyBtnView.choseLabel.text = self.resumeModel.HopeSalary;
    
    
    [eidtJobView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self.view);
    }];
    
    //self.userAccount = [UserAccount account];
    
    self.eidtJobView = eidtJobView;
}

#pragma mark 求职状态
-(void)showJobStatu{
    
    __weak typeof(self)weakSelf = self;
    
    [[MOFSPickerManager shareManger] showPickerViewWithDataArray:@[@"离职-随时到岗",@"在职-暂不考虑",@"在职-考虑机会",@"在职-月内到岗"] tag:67 title:@"选择工作状态" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString *string) {
        
        weakSelf.eidtJobView.jobStatuBtnView.choseLabel.text = string;
        
        weakSelf.eidtJobView.jobStatuBtnView.choseLabel.textColor = TFColor;
        
        //        weakSelf.userAccount.Sex = [string isEqualToString:@"男"]?@"0":@"1";
        
    } cancelBlock:^{
        
    }];
}
#pragma mark 职位
-(void)showJobWork{
    
    __weak typeof(self)weakSelf = self;
    
    SourceAlertView *sourceAlertView = [[SourceAlertView alloc] init];
    
    
    sourceAlertView.commitBlock = ^(NSString *str) {
        
        weakSelf.eidtJobView.jobWorkBtnView.choseLabel.text = str;
        
        weakSelf.eidtJobView.jobWorkBtnView.choseLabel.textColor = TFColor;
        
//        weakSelf.vipModel.Source = str;
    };
    
    [sourceAlertView showWithAnimation];
    
//    [[MOFSPickerManager shareManger] showPickerViewWithDataArray:@[@"私人教练",@"拳击教练",@"武术教练",@"其他"] tag:68 title:@"选择期望职位" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString *string) {
//        
//        weakSelf.eidtJobView.jobWorkBtnView.choseLabel.text = string;
//        
//        weakSelf.eidtJobView.jobWorkBtnView.choseLabel.textColor = TFColor;
//        
//        //        weakSelf.userAccount.Sex = [string isEqualToString:@"男"]?@"0":@"1";
//        
//    } cancelBlock:^{
//        
//    }];
//    
    
}
#pragma mark 显示城市
-(void)addressSelect{
    
    __weak typeof(self)weakSelf = self;
    
    [[MOFSPickerManager shareManger] showMOFSAddressPickerWithDefaultAddress:@"" title:@"选择城市" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString *address, NSString *zipcode) {
        
        weakSelf.eidtJobView.addressBtnView.choseLabel.text = address;
        
        weakSelf.eidtJobView.addressBtnView.choseLabel.textColor = TFColor;
        
        //        weakSelf.userAccount.Address = address;
        
    } cancelBlock:^{
        
        
    }];
}
#pragma mark 期望薪水
-(void)showJobMoney{
    
    __weak typeof(self)weakSelf = self;
    
    [[MOFSPickerManager shareManger] showPickerViewWithDataArray:@[@"5-8K",@"8-10K",@"10-12K",@"面议"] tag:70 title:@"选择期望薪水" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString *string) {
        
        weakSelf.eidtJobView.jobMoneyBtnView.choseLabel.text = string;
        
        weakSelf.eidtJobView.jobMoneyBtnView.choseLabel.textColor = TFColor;
        
        //        weakSelf.userAccount.Sex = [string isEqualToString:@"男"]?@"0":@"1";
        
    } cancelBlock:^{
        
    }];
}

#pragma mark - 确定

-(void)sureBtnClick
{
    if ([self.eidtJobView.jobStatuBtnView.choseLabel.text isEmptyString]) {
        
        [MBProgressHUD showText:@"请输入求职状态"];
        
        return;
        
    }
    if ([self.eidtJobView.jobWorkBtnView.choseLabel.text isEmptyString]) {
        
        [MBProgressHUD showText:@"请输入期望职位"];
        
        return;
        
    }
    if ([self.eidtJobView.addressBtnView.choseLabel.text isEmptyString]) {
        
        [MBProgressHUD showText:@"请输入期望城市"];
        
        return;
        
    }
    if ([self.eidtJobView.jobMoneyBtnView.choseLabel.text isEmptyString]) {
        
        [MBProgressHUD showText:@"请输入期望薪水"];
        
        return;
        
    }
    
    //地址选择
    self.resumeModel.HopeCity = self.eidtJobView.addressBtnView.choseLabel.text ;
    
    
    
    //求职状态
    self.resumeModel.HopeStatus = self.eidtJobView.jobStatuBtnView.choseLabel.text;
    
    //期望职位
    self.resumeModel.HopePosition = self.eidtJobView.jobWorkBtnView.choseLabel.text ;
    
    //薪水
    self.resumeModel.HopeSalary = self.eidtJobView.jobMoneyBtnView.choseLabel.text ;
    
//    if (self.saveResume) {
//        self.saveResume();
//    }
    
    //发送一个通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"resume" object:nil];
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
